﻿using ChestPainCenterSystem.Bll;
using ChestPainCenterSystem.Core;
using ChestPainCenterSystem.MedicalConfig;
using ChestPainCenterSystem.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ChestPainCenterSystem.Areas.ChestPainCenter.Controllers
{
    public class MedicalRecordSetController : BaseController
    {
        //
        // GET: /ChestPainCenter/MedicalRecordSet/

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            int medicalId = WebUtils.GetInt("medicalId");
            OperateResult resultInfo = MedicalRecordSetManager.GetMedicalConfig(medicalId);
            if (resultInfo.Result == 1)
            {
                var jsonobj = JsonConvert.DeserializeObject<dynamic>(resultInfo.Body.ToString());
                var result = new { Rows = jsonobj };
                return JsonDate(result);
            }
            return JsonDate(new { Total = 0, Rows = "" });
        }

        /// <summary>
        /// 添加/编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            ViewBag.Id = id;
            return View();
        }

        /// <summary>
        /// 添加/编辑病历主题
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Save(string data)
        {
            var json = JsonConvert.DeserializeObject<dynamic>(data);
            json.Create_User = loginUser.Name;
            json.Create_Time = DateTime.Now;
            OperateResult resultInfo = MedicalRecordSetManager.SetMedicalConfig(JsonHelper.JsonDate(json));
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 删除病历主题
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            OperateResult resultInfo = MedicalRecordSetManager.DelMedicalConfig(id);
            return JsonDate(resultInfo);
        }

    }
}
